﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>店面反结算收银</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/goodsSelecter.js"></script>
<script type="text/javascript" src="../js/vouchersTypeSelecter.js"></script>
<script type="text/javascript" src="../js/couponSelecterNew.js"></script>
<script type="text/javascript" src="../js/scheduleTypeSelecter.js"></script>
<script type="text/javascript" src="../js/lisenseSelecterNew.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 
<script type="text/javascript">
var _Discout = 1;
var _goodsList = new Array();
var _memberId = null;
var _Discout = null;
var _memberDeposit =  null;
var _memberId =  null;
var _cashCouponAmount = null;
var _sailId= null;
var copuonDetilId = 0;
var IntegralRule = 0;
var integralVote = 0;
$(function(){
	_sailId = getIdByName("saidId");
	
	
	$(".allMoney .check_btn").click(function(){
		var shopId = getInputValue("shop");
  		if(IsEmpty(shopId)){
  			artError("请先选择店铺")
  			return false;
  		}
		
		var giveMoney = $(".giveMoney").html();
		if(giveMoney==0){
			
		}else{
		$("#despoitMoney").attr("disabled",false);	
		$("#djqMoney").attr("disabled",false);		
		$("#faceMoney").val(giveMoney)	
		$("#allMoney").val(giveMoney)
		$("#wipeZeroAmt").val(0)
		$("#freeAmt").val(0)
		$("#fkMoney").val(giveMoney)
		$("#zlMoney").val(0)
		$("#coupMoney").val(giveMoney)
			$("#couponMoney").val(0)
		$("#gzMoney").val(0)
		$("#djqMoney").val(0)
		$("#posMoney").val(0)
		$("#lklAmt").val(0)
		$("#integralMoney").val(0)
			$("#dyqMoney").val(0)
		$("#dyqMoney2").val(0)
		$("#despoitMoney").val(0)
		$("#sk").val(0)
		if(IsEmpty(_memberId)){
			$("#despoitMoney").attr("disabled",true);	
			$("#djqMoney").attr("disabled",true);
			$("#ycfk").html("(非会员不可使用)")
			$("#jfdx").html("(非会员不可使用)")
			$("#djqfk").html("(非会员不可使用)")
		}else{
			if(IntegralRule==0){
				$("#integralMoney").attr("disabled",true);
				$("#jfdx").html("(暂无可用规则)")

			}else{
				$("#integralMoney").attr("disabled",false);
				$("#jfdx").html("(可用积分:"+_memberIntegral+",可用抵现金额："+(_memberIntegral/integralVote).toFixed(2)+")")
			}
			$("#ycfk").html("(可用预存："+ _memberDeposit +"元)")
			$("#djqfk").html("(可用代金券："+ _cashCouponAmount +"元)")
			
		}
		addMargin($(".coinHome"))
		
		$(".coinHome,#yinying1").show();
		if(IsNotEmpty(_memberId)){
			$("#despoitMoney").focus()
		}else{
			$("#coupMoney").focus()
		}
		}
	})
	$(".final").each(function(){
		$(this).text(parseFloat($(this).siblings(".theCoin").text())*(1-parseFloat($(".delMoney").text())).toFixed(2));
	})//单类商品总价
	
	$(".addNumber").live("keyup",function(){//修改
		/* var num=$(this).parent("td");
		num.siblings(".final").text(parseFloat(parseFloat($(this).val())*parseFloat(num.siblings(".theCoin").text())*(parseFloat(num.siblings(".delMoney").text()))).toFixed(2));
		num.parents("tbody").find(".final").length;
		var finaly=num.parents("tbody").find(".final") */
		var idName = $(this).attr("id")
		var id=idName.split("_")[1]
		var zk = $("#memberZk_"+id).val()
		var num = $("#goodsNum_"+id).val();
		var price = $("#goodsPrice_"+id).val();
		$("#goodsZk_"+id).html(parseFloat(zk*price).toFixed(2))
		$("#goodsMoney_"+id).html(parseFloat(zk*price*num).toFixed(2));
		getAllMoney();
		
	})
	
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
			$("#research").attr("disabled",false);
			
		}else{
			$("#shopName").attr("disabled",true);

		}
	});
	
	$(".receivedMoney").change(function(){
		var money = $(this).val()
		money = parseFloat(money);
		if(checkMoney(money)){
			$(this).val(money)
			var coupMoney = parseFloat( getInputValue("coupMoney")).toFixed(2);
			var gzMoney = parseFloat( getInputValue("gzMoney")).toFixed(2);
			var dyqMoney = parseFloat( getInputValue("dyqMoney")).toFixed(2);
			var dyqMoney2 = parseFloat( getInputValue("dyqMoney2")).toFixed(2);
			var despoitMoney =parseFloat( getInputValue("despoitMoney")).toFixed(2);
			var integralMoney =parseFloat( getInputValue("integralMoney")).toFixed(2);
			var djqMoney =parseFloat( getInputValue("djqMoney")).toFixed(2);
			var posMoney =parseFloat( getInputValue("posMoney")).toFixed(2);
			var lklAmt =parseFloat( getInputValue("lklAmt")).toFixed(2);
			var chkAmt =parseFloat( getInputValue("chkAmt")).toFixed(2);
			var couponMoney =parseFloat( getInputValue("couponMoney")).toFixed(2);
			var all=parseFloat(lklAmt)+parseFloat(integralMoney)+parseFloat(coupMoney)+parseFloat(couponMoney)+ parseFloat(dyqMoney)+ parseFloat(dyqMoney2)+ parseFloat(gzMoney)+parseFloat(despoitMoney)+parseFloat(djqMoney)+ parseFloat(posMoney)+ parseFloat(chkAmt)
			 $("#fkMoney").val(all)
		}else{
			$(this).val(0)
		}
	})
	
	$(".raceMoney").change(function(){
		var allMoney =parseFloat( getInputValue("allMoney")).toFixed(2);
		var wipeZeroAmt = getInputValue("wipeZeroAmt");
		var freeAmt = getInputValue("freeAmt");
		var facemoney = parseFloat(allMoney)- parseFloat(wipeZeroAmt)-parseFloat(freeAmt);
		 $("#faceMoney").val(facemoney.toFixed(2))
		 $("#coupMoney").val(facemoney.toFixed(2))
		 $("#fkMoney").val(facemoney.toFixed(2))
	})
	
	$("#goodsBarcode").keypress(function(event){
		if(event.keyCode==13){
		searchGoods();
		}
	})
	
	$("#sk").keypress(function(event){
		if(event.keyCode==13){
		 var sk = 	$(this).val().replace(/\s/gi,'')
		 var cash = getInputValue("coupMoney");
		 
		 $("#zlMoney").val((parseFloat(sk)- parseFloat(cash)).toFixed(2))
		}
	})
	resetMemberInfo();
	resetRoomInfo()
	getSailBill();
	getIntegralRule();
	getGoods()
})
function getIntegralRule(){
	var dt  = _findInfo("../memberIntRule/find/memberIntegralRuleByName", {'name':'积分抵现','status':1})
	if(IsNotEmpty(dt)&&dt.state==0){
		IntegralRule = _getIntOfJson(0, dt, "RuleID")
		integralVote = _getIntOfJson(0, dt, "IntegralRate");
	}
}

function getSailBill(){
	var SailBill = _findInfo("../saleBill/find/shopId/3/id/"+_sailId, null)
	if(IsNotEmpty(SailBill)&&SailBill.state==0){
		var htm= "<option value='"+_getIntOfJson(0, SailBill, "ShopID")+"'>"+_getIntOfJson(0, SailBill, "shopName")+"</option>"
		$("#shop").html(htm).attr("disabled",false)
		$("#shopIsChoosed").attr("checked","checked");
		$("#WipeZeroAmt").val(_getIntOfJson(0, SailBill, "WipeZeroAmt"))
		$("#ShouldAmt").val(_getIntOfJson(0, SailBill, "ShouldAmt"))
		$("#FactAmt").val(_getIntOfJson(0, SailBill, "FactAmt"))
		$("#FreeAmt").val(_getIntOfJson(0, SailBill, "FreeAmt"))
		$("#standNo").val(_getStringOfJson(0, SailBill, "StandNo"))
		$("#roomNo").val(_getStringOfJson(0, SailBill, "RoomNo"))
		$("#Maker").val(_getStringOfJson(0, SailBill, "Maker"))
		$("#MAKEDATE").val(_getStringOfJson(0, SailBill, "MAKEDATE"))
		$("#billNo").val(_getStringOfJson(0, SailBill, "billNo"))
		$("#memo").val(_getStringOfJson(0, SailBill, "Memo"))
		$("#status").val(_getStringOfJson(0, SailBill, "StaName"))
		
		$("#memberCardNo").val(_getStringOfJson(0, SailBill, "memberCardNo"))
		var htm="<option value='"+_getStringOfJson(0, SailBill, "scheduleTypeID")+"'>"+_getStringOfJson(0, SailBill, "scheduleTypeName")+"</option>"
		$("#ScheduleType").html(htm)
		getShopMember()
		/* var id= _getStringOfJson(0, SailBill, "ID");
		if(IsNotEmpty(id)){
			getSailBillPay(id)
			var SailBillDetil = _findInfo("../saleBill/find/shopId/"+_shopId+"/detl/"+id, null)
			if(SailBillDetil.state==0){
				loadDetil(SailBillDetil)
			}
		} */
	}
}

function getGoods(){
	var SailBillDetil = _findInfo("../saleBill/find/shopId/3/detl/"+_sailId, null)
	if(SailBillDetil.state==0){
		loadDetil(SailBillDetil)
	}
}

function resetMemberInfo(){
	_memberId = null;
	 _Discout = null;
	 _memberDeposit =  null;
	 _memberId =  null;
	 _cashCouponAmount = null;
	 _memberIntegral = 0;
	$("#cardNo").val("");
	$("#customerName").val("");
	$("#levelName").val("");
	$("#cashCouponAmount").val("");
	$("#depositAmount").val("");
	$("#discount").val("");
	restZk();
}

function getAllMoney(){
	var txt=0;
	for(var i=0,txt=0;i<$(".final").length;i++){
	 txt=parseFloat($(".final").eq(i).text())+parseFloat(txt);
	}
	$(".giveMoney").text(txt);//总价

}

function searchMember(){
	resetMemberInfo();
}

function searchMember(){
		
			var cardno = $("#memberCardNo").val().replace(/\s/gi,'')
			if(IsNotEmpty(cardno)){
				
				getShopMember();
			}else{
				
				resetMemberInfo();
			}	
}

function getShopMember(){//查询会员信息
	var shopId = getInputValue("shop");
	if(IsEmpty(shopId)){
		artError("请先选择店铺")
		return false;
	}
	var memberCardNo = getInputValue("memberCardNo")
	if(IsEmpty(memberCardNo)){
		return false;
	}
	var param = {'shopId':shopId,'memberCardNo':memberCardNo}
	var memberInfo = _findInfo("../shopmember/find/memberDespoist", param)
	if(IsNotEmpty(memberInfo)&&memberInfo.state==0){
		if(memberInfo.result.data.length==0){
			 _Discout = null;
			_cashCouponAmount = null;
			 _memberDeposit =  null;
			resetMemberInfo();
			
			alertErrorMessage("该会员卡号不存在")
		}else{
		$("#cardNo").val(memberCardNo);
		$("#levelName").val(_getStringOfJson(0, memberInfo, "levelName"))
		$("#integralAmount").val(_getStringOfJson(0, memberInfo, "integralAmount"))
		$("#customerName").val(_getStringOfJson(0, memberInfo, "customerName"))
		_Discout = _getStringOfJson(0, memberInfo, "discount");
		_memberDeposit = _getStringOfJson(0, memberInfo, "depositAmount")
		_cashCouponAmount = _getStringOfJson(0, memberInfo, "cashCouponAmount")
		_memberIntegral = _getStringOfJson(0, memberInfo, "integralAmount")
		_memberId = _getStringOfJson(0, memberInfo, "id")
		$("#discount").val(_Discout)
		$("#depositAmount").val(_memberDeposit)
		$("#cashCouponAmount").val(_cashCouponAmount)
		
		restZk()
		}		
	}
	
	$("#memberCardNo").val("");
}

function restZk(){
	$("#goodsList tbody tr").each(function() {
		/* var zk = IsEmpty(_Discout)?1:_Discout;
		 $(this).find("#").html(zk);
			var price = $(this).find(".theCoin").html()
		 $(this).find(".zkPrice").html((zk*price).toFixed(2) )
		 $(this).find(".final").html((zk*price*$(this).find(".addNumber").val()).toFixed(2) ) */
		 
		 var idName = $(this).attr("id")
		var id=idName.split("_")[1]
		var zk =IsEmpty(_Discout)?1:_Discout;
			$("#memberZk_"+id).val(zk)
		var num = $("#goodsNum_"+id).val();
		var price = $("#goodsPrice_"+id).val();
		$("#goodsZk_"+id).html(parseFloat(zk*price).toFixed(2))
		$("#goodsMoney_"+id).html(parseFloat(zk*price*num).toFixed(2));
		
	})
		getAllMoney();
}

function searchGoods(){
	getGoodsInfo();
}

function getGoodsInfo(){//查询商品信息
	var shopId = getInputValue("shop");
	if(IsEmpty(shopId)){
		artError("请先选择店铺")
		return false;
	}
	var goodsSelecter = getInputValue("goodsSelecter");
	var code= getInputValue("goodsBarcode");
	if(IsNotEmpty(code)){
		var params;
		if("barCode"==goodsSelecter){
		 params= {"barCode":code,"shopId":shopId}
		}else{
			 params= {"code":code,"shopId":shopId}
		}
		var goodsInfo = _findInfo("../goods/find/goodsListbyParams", params);
		
		if(IsNotEmpty(goodsInfo)&&goodsInfo.state==0){
			if(goodsInfo.result.data.length ==0){
				alertErrorMessage("查无商品")
			}else{
			var id=	_getStringOfJson(0, goodsInfo, "id");
			var flag = true;
			for ( var i = 0; i < _goodsList.length; i++) {
				if(id== _goodsList[i]){
					flag = false;
				}
			}
			
			var zk =(IsEmpty(_Discout)?1:_Discout);
			var promPrice = _getStringOfJson(0, goodsInfo, "promPrice");
			var price =  IsEmpty(promPrice)? _getStringOfJson(0, goodsInfo, "salePrice"):promPrice;
			var memo = "";
			if(IsNotEmpty(promPrice)){
				memo= "促销商品";
			}
				
			if(flag){
				var htm ="<tr id=\"goodsId_"+id+"\"><td> <input type='hidden' class='goodsId' value='"+id+"'/> "+ _getStringOfJson(0, goodsInfo, "barcode") +" </td><td>"+ _getStringOfJson(0, goodsInfo, "code") +" </td>  <td> "+ _getStringOfJson(0, goodsInfo, "name") +"</td><td>"+ _getStringOfJson(0, goodsInfo, "mode") +"</td>   <td><input id=\"goodsNum_"+id+"\" class=\"addNumber\" type=\"text\" value=\"1\"></td>"+
				"<td class=\"theCoin\" ><input id=\"goodsPrice_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+price +"\"></td><td class=\"delMoney\"><input id=\"memberZk_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+ zk  +"\"></td> <td id=\"goodsZk_"+id+"\" class=\"zkPrice\">"+ (zk * price).toFixed(2)  +"</td> <td class=\"final\" id=\"goodsMoney_"+id+"\">"+(price*zk).toFixed(2)+"</td> "+
				" <td id=\"goodsMemo_"+id+"\">"+memo+"</td> <td><input class=\"common_btn del\" type=\"button\" value=\"删除\" onclick=\"deleteTr("+id+")\" ></td></tr>"
				$("#goodsList tbody").append(htm);
			_goodsList.push(id);
			}else{
				var number = parseInt($("#goodsNum_"+id).val())+1;
				var price = parseFloat($("#goodsPrice_"+id).val())
				var rowPrice = price * number * (IsEmpty(_Discout)?1:_Discout)
				$("#goodsNum_"+id).val(number)
				$("#goodsMoney_"+id).html(rowPrice.toFixed(2))
			}
			getAllMoney();
			}
			
		}
		
	}else{
		alertErrorMessage("请填写商品码")
	}
}

function quickAddGoods(){
	var shopId = getInputValue("shopName");

	var haveId = new Array('GSF','CLF',"BF","FJ")
	for ( var i = 0; i < haveId.length; i++) {
		var bc = haveId[i]
		var params= {"barCode":bc,"shopId":shopId}
		var goodsInfo = _findInfo("../goods/find/goodsListbyParams", params);
		
		if(IsNotEmpty(goodsInfo)&&goodsInfo.state==0){
			if(goodsInfo.result.data.length ==0){
			}else{
			var id=	_getStringOfJson(0, goodsInfo, "id");
			var flag = true;
			for ( var i = 0; i < _goodsList.length; i++) {
				if(id== _goodsList[i]){
					flag = false;
				}
			}
			
			var zk =(IsEmpty(_Discout)?1:_Discout);
			var promPrice = _getStringOfJson(0, goodsInfo, "promPrice");
			var price =  IsEmpty(promPrice)? _getStringOfJson(0, goodsInfo, "salePrice"):promPrice;
			var memo = "";
			if(IsNotEmpty(promPrice)){
				memo= "促销商品";
			}
				
			if(flag){
			var htm ="<tr id=\"goodsId_"+id+"\"><td> <input type='hidden' class='goodsId' value='"+id+"'/> "+ _getStringOfJson(0, goodsInfo, "barcode") +" </td><td>"+ _getStringOfJson(0, goodsInfo, "code") +" </td>  <td> "+ _getStringOfJson(0, goodsInfo, "name") +"</td><td>"+ _getStringOfJson(0, goodsInfo, "mode") +"</td>   <td><input id=\"goodsNum_"+id+"\" class=\"addNumber\" type=\"text\" value=\"1\"></td>"+
			"<td class=\"theCoin\" ><input id=\"goodsPrice_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+price +"\"></td><td class=\"delMoney\"><input id=\"memberZk_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+ zk  +"\"></td> <td id=\"goodsZk_"+id+"\" class=\"zkPrice\">"+ (zk * price).toFixed(2)  +"</td> <td class=\"final\" id=\"goodsMoney_"+id+"\">"+(price*zk).toFixed(2)+"</td> "+
			" <td id=\"goodsMemo_"+id+"\">"+memo+"</td> <td><input class=\"common_btn del\" type=\"button\" value=\"删除\" onclick=\"deleteTr("+id+")\" ></td></tr>"
			$("#goodsList tbody").append(htm);
			_goodsList.push(id);
			}else{
				addGoodsById(id);
			}
			getAllMoney();
			}
			
		}
	}
	
}

function deleteTr(id){
	art.dialog({fixed:true, lock: true,content:"确认删除该条数据？",icon:'question',ok: function(){

		$("#goodsId_"+id).remove();
		_goodsList = new Array();
		
		$(".goodsId").each(function (){
			_goodsList.push($(this).val())
		})
		getAllMoney();
	
	},cancel:true});

	
}

function checkFk(){
	var dyqMoney = $("#dyqMoney").val()
	var dyqMoney2 = $("#dyqMoney2").val()
	var voucherTypeId =$("#voucherTypeId").val();
	var voucherTypeId2 =$("#voucherTypeId2").val();
	if(dyqMoney>0){
		if(IsEmpty(voucherTypeId)){
			art.dialog({fixed:true, lock: true,content:"请选择要使用的抵用券类型",icon:'question',ok: true})
			return false;
		}		
	}
	if(dyqMoney2>0){
		if(IsEmpty(voucherTypeId2)){
			art.dialog({fixed:true, lock: true,content:"请选择要使用的材料抵用券类型",icon:'question',ok: true})
			return false;
		}		
	}
		var faceMoney = getInputValue("faceMoney");
		var fkMoney = getInputValue("fkMoney");
		if(parseFloat( fkMoney) == parseFloat( faceMoney )){
			art.dialog({fixed:true, lock: true,content:"确认收款完成？",icon:'question',ok: function (){		
				saveInfo()
			},cancel:true});
		}else if(parseFloat( fkMoney) < parseFloat( faceMoney )){
			artError("付款不足")
			return false;
		}else if(parseFloat( fkMoney) > parseFloat( faceMoney )){
			art.dialog({fixed:true, lock: true,content:"付款("+fkMoney+")大于实收("+faceMoney+"),是否确定交易？",icon:'question',ok: function (){
				saveInfo()
			},cancel:true});
		}
		
	
}
function addInfo(){
	
	if(IsNotEmpty(_memberId)){
		var despoitMoney = getInputValue("despoitMoney");
		var djqMoney = getInputValue("djqMoney");
		if(despoitMoney>0||djqMoney>0){
			$("#toPassword,#yinying2").show();
			$("#password").focus()
		}else{
			saveInfo()
		}
	}else{
		saveInfo()
	}	
	
}
function saveInfo(){
	var shopId = getInputValue("shop");
	var standNo = getInputValue("standNo");
	var roomNo = getInputValue("roomNo");
	var giveMoney = getHtmlValue("giveMoney");
	var consumeAmt = getInputValue("allMoney");
	var faceMoney = getInputValue("faceMoney");
	var wipeZeroAmt = getInputValue("wipeZeroAmt");
	var freeAmt = getInputValue("freeAmt");
	var gzMoney = getInputValue("gzMoney");
	var coupMoney = getInputValue("coupMoney");
	var couponMoney = getInputValue("couponMoney");
	var despoitMoney = getInputValue("despoitMoney");
	var integralMoney = getInputValue("integralMoney");
	var djqMoney = getInputValue("djqMoney");
	var lklAmt = getInputValue("lklAmt");
	var posMoney = getInputValue("posMoney");
	var memo = getInputValue("memo");
	var cardNo = getInputValue("cardNo");
	var chkAmt = getInputValue("chkAmt");
	var password = getInputValue("password");
	var dyqMoney = getInputValue("dyqMoney");
	var dyqMoney2 = getInputValue("dyqMoney2");
	var voucherMemo = $("#voucherTypeId").text();
	var voucherMemo2 = $("#voucherTypeId2").text()
	var fkMoney = getInputValue("fkMoney");
	var billNo = $("#billNo").val();
	
/* 	alert(fkMoney+":"+faceMoney)
 */	
	var ScheduleTypeId = getInputValue("ScheduleType");
	
	var heads = new Array("ShopID","MemberID","CardNo","Memo","RoomNo","StandNo","ConsumeAmt","ServiceAmt","WipeZeroAmt","ShouldAmt","FactAmt","FreeAmt","sdeTypeId","billNo","id")
	var datas = new Array(shopId,_memberId,cardNo,memo,roomNo,standNo,consumeAmt,null,wipeZeroAmt, consumeAmt,faceMoney,freeAmt,ScheduleTypeId,billNo,_sailId)
	var jsonDate= _getJsonParseEditStr(heads, datas);
	
	var payHead=new Array("integralAmt","cashAmt","regAmt","depstAmt","bnkAmt","chkAmt","cashCoupAmt","voucherAmt","voucherAmt2","couponAmt","voucherMemo","voucherMemo2","lklAmt")
	var payData= new Array(integralMoney,coupMoney,gzMoney,despoitMoney,posMoney,chkAmt,djqMoney,dyqMoney,dyqMoney2,couponMoney,voucherMemo,voucherMemo2,lklAmt);
	
	var payJsonData = _getJsonParseInsertStr(payHead, payData);
	var parser2 = new Object();
	var jsonParserStr2 = null;

	var i= 0;
	var isMember = null;
	if(IsNotEmpty(_memberId)){
		isMember = 1;
	}
	
	$("#goodsList tbody tr").each(function(){
		var id= $(this).find("td:first").find("input").val()
		i++;
		 var zk =  $("#memberZk_"+id).val()
		 zk = IsEmpty(zk)?1:zk;
		var head=new Array("no","keep","give","Nums","factPrice","salePrice","status","goodsId","member","memDict","memo")
		var data=new Array(i,0,0,getInputValue("goodsNum_"+id),getHtmlValue("goodsZk_"+id),$("#goodsPrice_"+id).val(),0,id,isMember,zk,getHtmlValue("goodsMemo_"+id))
		if (IsNotEmpty(data)){
			addToParser(head, data, "add" , parser2);
			jsonParserStr2 =  JSON.stringify(parser2);
			}
		})
		var voucherTypeId =$("#voucherTypeId").val();
	
/* 	var dt = _insertInfoNoSucceedMessage("../saleBill/edit/editInfo", {"data":jsonDate,"detl":jsonParserStr2,"pay":payJsonData,"shopId" : shopId,"id" : _sailId,"password":password})
	if(IsNotEmpty(dt)&&dt.state==0){
		var id= getHeadIndexValue(0, dt, "id"); */
		var m= null;
		 if(IsEmpty(_memberId)){
			 m = _insertInfoNoSucceedMessage("../saleBill/edit/editNormal", {"data":jsonDate,"detl":jsonParserStr2,"pay":payJsonData,"shopId" : shopId,"id" : _sailId,"shopId":shopId,"voucherTypeId":voucherTypeId,"copuonDetilId":copuonDetilId})
		}else{
			 m = _insertInfoNoSucceedMessage("../saleBill/edit/editMember", {"data":jsonDate,"detl":jsonParserStr2,"pay":payJsonData,"shopId" : shopId,"id" : _sailId,"shopId":shopId,"voucherTypeId":voucherTypeId,"copuonDetilId":copuonDetilId})			
		}
		 if(IsNotEmpty(m)){
			 if(m.state==0){
				 removeAllGoods();
/* 				 resetMemberInfo();
 */				 resetRoomInfo();
				 if(IsNotEmpty(m)){
					 if(m.state==0){
						 art.dialog({fixed:true, lock: true,content:"交易完成,是否打印销售单？",icon:'question',ok:function(){
							 toPrintSaleBill($("#billNo").val(),$("#shop").val())
						 },cancel:true});	
					 }
				 }
				$(".coinHome,#yinying1").hide();
				$("#toPassword,#yinying2").hide();

			 }
		 }
	}
	
/* } */

function toPrintSaleBill(billNo,shopId){
	window.open('printSaleBill.html?billNo='+billNo+'&shopId='+shopId+"&flag=2")

}


function removeAllGoods(){
	_goodsList = new Array();
	$("#goodsList tbody").empty();
	$("#giveMoney").html(0)
}

function resetRoomInfo(){
	$("#standNo").val("")
	$("#memo").val("")
	$("#roomNo").val("")
	$("#goodsBarcode").val("");
}

function loadDetil(json){
	for ( var i = 0; i < json.result.data.length; i++) {
		var barCode = _getStringOfJson(i, json, "barCode")
		var nums = _getStringOfJson(i, json, "Nums")
		//getOldGoodsInfo(barCode,Nums)MemDict
		var id=	_getStringOfJson(i, json, "GoodsID");
		var flag = true;
		for ( var i = 0; i < _goodsList.length; i++) {
			if(id== _goodsList[i]){
				flag = false;
			}
		}
		var zk =_getStringOfJson(i, json, "MemDict")
		 zk =(IsEmpty(zk)?1:zk);
		var price =  _getStringOfJson(i, json, "SalePrice")
		var memo =  _getStringOfJson(i, json, "memo");
		
			
		if(flag){
		var htm ="<tr id=\"goodsId_"+id+"\"><td> <input type='hidden' class='goodsId' value='"+id+"'/> "+ _getStringOfJson(i, json, "barCode") +" </td><td>"+ _getStringOfJson(i, json, "goodsCode") +" </td>  <td> "+ _getStringOfJson(i, json, "goodsName") +"</td><td>"+ _getStringOfJson(i, json, "mode") +"</td>   <td><input id=\"goodsNum_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+nums+"\"></td>"+
		"<td class=\"theCoin\"><input id=\"goodsPrice_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+price +"\"></td><td class=\"delMoney\"><input id=\"memberZk_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+ zk  +"\"></td> <td id=\"goodsZk_"+id+"\" class=\"zkPrice\">"+ (zk * price).toFixed(2)  +"</td> <td class=\"final\" id=\"goodsMoney_"+id+"\">"+(price*zk*nums).toFixed(2)+"</td> "+
		" <td id=\"goodsMemo_"+id+"\">"+memo+"</td> <td><input class=\"common_btn del\" type=\"button\" value=\"删除\" onclick=\"deleteTr("+id+")\" ></td></tr>"
		$("#goodsList tbody").append(htm);
		_goodsList.push(id);
		}else{
			var number = parseInt($("#goodsNum_"+id).val())+1;
			var price = parseFloat($("#goodsPrice_"+id).val())
			var rowPrice = price * number * (IsEmpty(_Discout)?1:_Discout)
			$("#goodsNum_"+id).val(number)
			$("#goodsMoney_"+id).html(rowPrice.toFixed(2))
		}
		getAllMoney();
			}
}


function getOldGoodsInfo(barCode,nums){//查询商品信息
	var shopId = getInputValue("shop");
	if(IsNotEmpty(barCode)){
		var params;
		 params= {"barCode":barCode,"shopId":shopId}
		var goodsInfo = _findInfo("../goods/find/goodsListbyParams", params);
		
		if(IsNotEmpty(goodsInfo)&&goodsInfo.state==0){
			if(goodsInfo.result.data.length ==0){
			}else{
			var id=	_getStringOfJson(0, goodsInfo, "id");
			var flag = true;
			for ( var i = 0; i < _goodsList.length; i++) {
				if(id== _goodsList[i]){
					flag = false;
				}
			}
			
			var zk =(IsEmpty(_Discout)?1:_Discout);
			var promPrice = _getStringOfJson(0, goodsInfo, "promPrice");
			var price =  IsEmpty(promPrice)? _getStringOfJson(0, goodsInfo, "salePrice"):promPrice;
			var memo = "";
			if(IsNotEmpty(promPrice)){
				memo= "促销商品";
			}
				
			if(flag){
			var htm ="<tr id=\"goodsId_"+id+"\"><td> <input type='hidden' class='goodsId' value='"+id+"'/> "+ _getStringOfJson(0, goodsInfo, "barcode") +" </td><td>"+ _getStringOfJson(0, goodsInfo, "code") +" </td>  <td> "+ _getStringOfJson(0, goodsInfo, "name") +"</td><td>"+ _getStringOfJson(0, goodsInfo, "mode") +"</td>   <td><input id=\"goodsNum_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+nums+"\"></td>"+
			"<td class=\"theCoin\"><input id=\"goodsPrice_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+price +"\"></td><td class=\"delMoney\"><input id=\"memberZk_"+id+"\" class=\"addNumber\" type=\"text\" value=\""+ zk  +"\"></td> <td id=\"goodsZk_"+id+"\" class=\"zkPrice\">"+ (zk * price).toFixed(2)  +"</td> <td class=\"final\" id=\"goodsMoney_"+id+"\">"+(price*zk*nums).toFixed(2)+"</td> "+
			" <td id=\"goodsMemo_"+id+"\">"+memo+"</td> <td><input class=\"common_btn del\" type=\"button\" value=\"删除\" onclick=\"deleteTr("+id+")\" ></td></tr>"
			$("#goodsList tbody").append(htm);
			_goodsList.push(id);
			}else{
				var number = parseInt($("#goodsNum_"+id).val())+1;
				var price = parseFloat($("#goodsPrice_"+id).val())
				var rowPrice = price * number * (IsEmpty(_Discout)?1:_Discout)
				$("#goodsNum_"+id).val(number)
				$("#goodsMoney_"+id).html(rowPrice.toFixed(2))
			}
			getAllMoney();
			}
			
		}
		
	}
}

function goodsSelected(goodsId, goodsName, barCode) {
	$("#goodsSelecter").val("barCode");
	$("#goodsBarcode").val(barCode);
	searchGoods();
}
function closePassword(){
	$("#toPassword").hide();
	$("#yinying2").hide()
}
function openCouponList(){
	var shopId =getInputValue("shop")
	if(IsEmpty(shopId)){
		alert("请选择店铺");
		return fasle;
	}
	openCouponListPanel("couponMoney",_memberId,shopId)
}
function addGoodsById(id){
	var zk = $("#memberZk_"+id).val()
	var num = parseInt( $("#goodsNum_"+id).val())+1;
	$("#goodsNum_"+id).val(num)
	var price = $("#goodsPrice_"+id).val();
	$("#goodsZk_"+id).html(parseFloat(zk*price).toFixed(2))
	$("#goodsMoney_"+id).html(parseFloat(zk*price*num).toFixed(2));
	getAllMoney();
}
function __couponSelected(id,value){
	$("#couponListPanel, #couponListPanel_yinying").hide();
	$("#couponMoney").val(value);
	copuonDetilId = id;
	var coupMoney = parseFloat( getInputValue("coupMoney")).toFixed(2);
	var dyqMoney = parseFloat( getInputValue("dyqMoney")).toFixed(2);
	var dyqMoney2 = parseFloat( getInputValue("dyqMoney2")).toFixed(2);
	var gzMoney = parseFloat( getInputValue("gzMoney")).toFixed(2);
	var despoitMoney =parseFloat( getInputValue("despoitMoney")).toFixed(2);
	var djqMoney =parseFloat( getInputValue("djqMoney")).toFixed(2);
	var posMoney =parseFloat( getInputValue("posMoney")).toFixed(2);
	var lklAmt =parseFloat( getInputValue("lklAmt")).toFixed(2);
	var chkAmt =parseFloat( getInputValue("chkAmt")).toFixed(2);
	var couponMoney =parseFloat( getInputValue("couponMoney")).toFixed(2);
	
	var all=parseFloat(lklAmt)+parseFloat(coupMoney)+parseFloat(couponMoney)+ parseFloat(dyqMoney)+ parseFloat(dyqMoney2)+ parseFloat(gzMoney)+parseFloat(despoitMoney)+parseFloat(djqMoney)+ parseFloat(posMoney)+ parseFloat(chkAmt)
	 $("#fkMoney").val(all)
}

</script>
<div id="yinying1"></div>
<div id="yinying2" style="z-index: 599"></div>
<div class="hideDiv member_search" id="toPassword" style="z-index: 600" >
	<div class="closeTop"><span onclick="closePassword()" class="closeThe"><img src="../images/close.png"></span></div>
    <p><span>密码：</span><input type="password" id="password" style="width:450px;height:30px;line-height:30px;"></p>
    <div class="BottomBtn"><input type="button"  value="确定" onclick="saveInfo()"><input type="button"  onclick="closePassword()" value="取消"></div>
</div>
<div class="hideDiv coinHome member_search">
  <div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
  <p>
      <label><span>应收：</span>
        <input type="text" id="allMoney" readonly="readonly">
      </label>
   	
     
      </p>
     <p>
      <label><span>抹零：</span>
        <input type="text" id="wipeZeroAmt" value="0"  class="raceMoney">
      </label>
   
      <label><span>免单：</span>
       	<input type="text" id ="freeAmt" value="0"  class="raceMoney">
      </label>
      </p>
      
      <p>
       <label><span>实收：</span>
       	<input type="text" id="faceMoney" value="0"  readonly="readonly">
      </label>
      </p>
     <p style="padding-top: 10px; border-top: 2px solid rgb(220, 220, 220);">
      <label><span>现金付款：</span>
        <input type="text" id="coupMoney" value="0" class="receivedMoney">
      </label>
   
      <label><span>挂账付款：</span>
       	<input type="text" id="gzMoney" value="0"  class="receivedMoney">
      </label>
      </p>
 	 <p>
      <label><span>POS付款：</span>
        <input type="text" id="posMoney" value="0"  class="receivedMoney">
      </label>
       <label><span>支票付款：</span>
        <input type="text" id="chkAmt" value="0"  class="receivedMoney">
      </label>
      </p>
       <p style="display: none;">
      <label><span>拉卡拉：</span>
        <input type="text" id="lklAmt" value="0"  class="receivedMoney">
      </label>
       
      </p>	
      	 <p>
      <label><span>预存付款：</span>
        <input type="text" id="despoitMoney" value="0"  class="receivedMoney">
      </label>
      <label><span id="ycfk">(可用金额：)</span>
      </label>
   		</p><p>
      <label><span>代金券付款：</span>
       	<input type="text" id ="djqMoney" value="0"  class="receivedMoney">
      </label>
      <label><span id="djqfk">(可用金额：)</span>
      </label>
      </p>
     <p>
    <label><span>积分抵现：</span>
      <input type="text" id="integralMoney" value="0"  class="receivedMoney">
    </label>
    <label><span id="jfdx"> (可用积分：)</span> </label>
  </p>
      <p>
    <label><span>工时抵用券：</span>
      <input type="text" id ="dyqMoney" value="0"  class="receivedMoney">
    </label>
    <label><span>抵用券选择：</span>
      <select id="voucherTypeId" onclick="openvouchersListPanel(this)">
      </select>
    </label>
  </p>
  <p>
    <label><span>材料抵用券：</span>
      <input type="text" id ="dyqMoney2" value="0"  class="receivedMoney">
    </label>
    <label><span>抵用券选择：</span>
      <select id="voucherTypeId2" onclick="openvouchersListPanel(this)">
      </select>
    </label>
  </p>
      <p>
    <label><span>优惠劵：</span>
      <input type="text" id ="couponMoney" value="0" onclick="openCouponList()"  class="receivedMoney">
    </label>
  </p>
       <p >
      <label><span>总付款：</span>
        <input type="text" id="fkMoney" value="0" readonly="readonly" class="receivedMoney">
      </label>

      </p>
       <p style="padding-top: 10px; border-top: 2px solid rgb(220, 220, 220);">
      <label><span>收款：</span>
        <input type="text" id="sk" value="0" >
      </label>
   
      <label><span>找零：</span>
       	<input type="text" id="zlMoney" value="0" readonly="readonly"   class="receivedMoney">
      </label>
      </p>
     
       
  <div class="BottomBtn"><input type="button" value="确认付款" onclick="checkFk()"></div>
</div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">店面反结算收银</div>
    <div class="member_search">
      <p><span>
      	 <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">
        		店面：</span>
        <select id="shop" onclick="openShopListPanel(this)" style=";height:20px;" disabled="disabled">
        </select>
         <span>服务项目：</span>
        <select id="ScheduleType" onclick="openScheduleTypeListPanel(this)" style=";height:20px;" >
        </select>
        <span>单据号：</span>
        <input type="text" value="" id="billNo" readonly="readonly"">
        </p>
        <p> <span>单号：</span>
        <input type="text" value="" id="standNo" class="absoluteTxt">
        <span>房间/车牌号：</span>
        <input type="text" value="" id="roomNo" class="absoluteTxt">
<!--         <input class="btn common_btn" type="button" onclick="openLisenseListPanel(this)" value="选择" >
 -->       
      </p>
      <p>
       <span>备注：</span>
        <input type="text" value="" id="memo" class="absoluteTxt">
      </p>
     </br>
      <div class="knowPerson">
      <p style="display: none;" class="knowAll">
        <label> <span>会员卡号：</span>
          <input type="text" id="memberCardNo" class="absoluteTxt"  onkeypress="if(event.keyCode==13){searchMember()}" >
        </label>
        <input class="btn common_btn" name="查询" type="button" value="清除会员信息" onclick="resetMemberInfo()" >
        </p> 
      <p class="knowAll">
        <label> <span>会员卡号：</span>
          <input type="text" readonly id="cardNo" class="memberInfo">
        </label>
        <label> <span>会员姓名：</span>
          <input type="text" readonly id="customerName" class="memberInfo">
        </label>
        <label> <span>会员级别：</span>
          <input type="text" id="levelName" readonly="readonly" class="memberInfo">
        </label>
        </p>
      <p class="knowAll">
       
        <label> <span>预存金额：</span>
          <input type="text" readonly id="depositAmount" class="memberInfo">
        </label>
         <label> <span>代金券：</span>
          <input type="text" readonly id="cashCouponAmount" class="memberInfo">
        </label>
         <label> <span>会员折扣：</span>
          <input type="text" readonly id="discount" class="memberInfo">
        </label>
        </p>
      </div>
    </div>
    <div class="member_search" style="margin-top:15px;margin-bottom:-10px;">
     <select id="goodsSelecter"><option value="barCode">商品条码</option><option value="code">商品编码</option></select>
          <input type="text"  id="goodsBarcode" class="memberInfo absoluteTxt"  >
             <select id="goodsIdSlecter" onclick="openGoodsListPanel(this)"></select>
        <input class="btn common_btn" name="查询" type="button" value="添加"  onclick="searchGoods()">
       <input class="btn common_btn"type="button" value="快速添加"  onclick="quickAddGoods()">
    </div>
    <table id="goodsList" width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0">
      <caption>
     <strong> 商品列表 </strong> <!-- <a href="javascript:void(0)" onclick="downRescouse()">导出数据</a> --><input type="button" class="common_btn" onclick="removeAllGoods()" value="全部删除">
      </caption>
      <thead>
        <tr>
          <th>商品条码</th>
          <th>商品编码</th>
          <th>商品名称</th>
          <th>规格型号</th>
          <th>数量</th>
          <th>折前单价</th>
          <th>折扣率</th>
          <th>折后单价</th>
          <th>小计</th>
          <th>备注</th>
          <th>操作</th>
        </tr>
      </thead>
       <tbody>
       
       </tbody> 
    </table>
    <div class="allMoney"><span>总金额(折算后)：</span><strong id="giveMoney" class="giveMoney">0</strong><br><input type="button" class="check_btn common_btn" value="结算" ></div>
    <div id="pager" style="float: right;"></div>
  </div>
  <div class="fc"></div>
</div>

<div id="goodsListPanel_yinying" class="yinying" style="z-index:499;"></div>
		<div  style="z-index:500;" id="goodsListPanel" class="hideDiv">
			<div style="float: right; margin-bottom: 5px; width: 20px; height: 20px; line-height: 20px; text-align: center; background-color: #eee; margin-bottom: 5px; border: 1px solid #ccc;">
				<span id="goodsListPanel_close" style="cursor: pointer; font-size: 14px;">X</span>
			</div>
			<div class="bottom_search">
				<div class="serWrapper" >
					<input type="text" id="goodsListPanel_searchName" class="txt" >
					<strong class="refresh" onclick="$(this).prev().val('')">清空</strong>
				</div>
				<input type="button" id="goodsListPanel_search"
				style="width: auto; margin-left: 5px;" value="查询"
				class="common_btn">
			</div>
			<table cellpadding="4" cellspacing="0" border="1" width="100%">
				<thead>
					<tr>
						<th>商品Id</th>
						<th>商品名称</th>
						<th>商品扫描码</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="goodsListPanel_data" ></tbody>
			</table>
			<div id="goodsPager" class="pager" ></div>
		</div>
<!-- InstanceEndEditable --> 
	<div id="vouchersListPanel_yinying" class="yinying" style="z-index:499;"></div>
		<div  style="z-index:500;" id="vouchersListPanel" class="hideDiv">
			<div style="float: right; margin-bottom: 5px; width: 20px; height: 20px; line-height: 20px; text-align: center; background-color: #eee; margin-bottom: 5px; border: 1px solid #ccc;">
				<span id="vouchersListPanel_close" style="cursor: pointer; font-size: 14px;">X</span>
			</div>
			<div class="bottom_search">
				<div class="serWrapper" >
					<input type="text" id="vouchersListPanel_search" class="txt" >
					<strong class="refresh" onclick="$(this).prev().val('')">清空</strong>
				</div>
				<input type="button" id="goodsListPanel_search"
				style="width: auto; margin-left: 5px;" value="查询"
				class="common_btn">
			</div>
			<table cellpadding="4" cellspacing="0" border="1" width="100%">
				<thead>
					<tr>
						<th>抵用券Id</th>
						<th>抵用券名称</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="vouchersListPanel_data" ></tbody>
			</table>
			<div id="vouchersPager" class="pager" ></div>
		</div>
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
addMargin($(".hideDiv"))
clearThis("absoluteTxt");
showTab(7,4);
</script>
</body>
<!-- InstanceEnd -->
</html>
